<fieldset class="layui-elem-field">
    <legend>添加合同</legend>
    <div class="layui-field-box">
        <form action="{:url('Contract/addcontract')}" class="layui-form   ajax-form" method="post"
              style="margin: 20px">
            <div class="layui-row">
                <div class="layui-col-md6">

                    <div class="layui-form-item">
                        <label class="layui-form-label">合作单位</label>
                        <div class="layui-input-inline">
                            <select name="company_id" lay-filter="selectId" lay-verify="required">
                                <option value="">公司名称</option>
                                {volist name="company" id="c"}
                                <option value="{$c.company_id}">{$c.company_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">合作周期</label>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="start_time" value=""
                                           autocomplete="off" class="layui-input laydate-date-start" placeholder="请选择开始时间"  >
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="end_time" value=""
                                           autocomplete="off" class="layui-input laydate-date-end" placeholder="请选择结束时间">
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">合作内容</label>
                        <div class="layui-inline">
                            <textarea class="layui-textarea" id="LAY_demo1" style="display: none" name="content"></textarea>
                        </div>
                    </div>



                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label"> </label>
                <button class="layui-btn" lay-submit="">确定</button>
                <a class="layui-btn  layui-btn-primary" href="{:url('Contract/contractlist')}">返回</a>
            </div>
        </form>
    </div>
</fieldset>

<script>
    layui.use(['layedit','element', 'table', 'layer', 'form', 'upload'],function(){
        var layer = layui.layer;
        var form = layui.form;
        var layedit = layui.layedit
            ,$ = layui.jquery;
        layedit.set({
            uploadImage: {
                url: '{:url("Common/uploads")}' //接口url
            }
        });
        //构建一个默认的编辑器
        var index = layedit.build('LAY_demo1',{
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线

                ,'|' //分割线

                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'link' //超链接
                ,'unlink' //清除链接
                ,'image'//上传托iN

            ]
        });

        //编辑器外部操作
        var active = {
            content: function(){
                alert(layedit.getContent(index)); //获取编辑器内容
            }
            ,text: function(){
                alert(layedit.getText(index)); //获取编辑器纯文本内容
            }
            ,selection: function(){
                alert(layedit.getSelection(index));
            }
        };
        form.on('submit(ajax-layedit)', function (data) {
            var loading = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            var url = data.form.action;
            var method = data.form.method;
            var d = data.field;
            console.log(layedit.getContent(layedit_index));
            d.content = layedit.getContent(layedit_index);
            $.ajax({
                type: method,
                url: url,
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    layer.close(loading);
                    msg = res.msg ? res.msg : '网络错误';
                    layer.msg(msg);
//                    jumpUrl = res.jumpUrl;
//                    if (res.code == 200) {
//                        if (jumpUrl) {
//                            window.location.href = jumpUrl;
//                        } else {
//                            window.location.reload();
//                        }
//                    }
                },
                error: function (res) {
                    layer.close(loading);
                    layer.msg("网络错误");
                }
            });
            return false;
        });
        //自定义工具栏
        layedit.build('LAY_demo2', {
            tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
            ,height: 100
        })
    });
</script>